package com.xintai.sparepart.spareandpart.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.sparepart.spareandpart.domain.BeiClients;
import com.xintai.sparepart.spareandpart.service.IBeiClientsService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 备品备件客户管理Controller
 *
 * @author xintai
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/sparepart/clients")
public class BeiClientsController extends BaseController
{
    @Autowired
    private IBeiClientsService beiClientsService;

    /**
     * 查询备品备件客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:list')")
    @GetMapping("/list")
    public TableDataInfo list(BeiClients beiClients)
    {
        startPage();
        List<BeiClients> list = beiClientsService.selectBeiClientsList(beiClients);
        return getDataTable(list);
    }

    /**
     * 导出备品备件客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:export')")
    @Log(title = "备品备件客户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BeiClients beiClients)
    {
        List<BeiClients> list = beiClientsService.selectBeiClientsList(beiClients);
        ExcelUtil<BeiClients> util = new ExcelUtil<BeiClients>(BeiClients.class);
        return util.exportExcel(list, "clients");
    }

    /**
     * 获取备品备件客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:query')")
    @GetMapping(value = "/{beiId}")
    public AjaxResult getInfo(@PathVariable("beiId") Long beiId)
    {
        return AjaxResult.success(beiClientsService.selectBeiClientsById(beiId));
    }

    /**
     * 新增备品备件客户管理
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:add')")
    @Log(title = "备品备件客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BeiClients beiClients)
    {
        return toAjax(beiClientsService.insertBeiClients(beiClients));
    }

    /**
     * 修改备品备件客户管理
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:edit')")
    @Log(title = "备品备件客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BeiClients beiClients)
    {
        return toAjax(beiClientsService.updateBeiClients(beiClients));
    }

    /**
     * 删除备品备件客户管理
     */
    @PreAuthorize("@ss.hasPermi('sparepart:clients:remove')")
    @Log(title = "备品备件客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{beiIds}")
    public AjaxResult remove(@PathVariable Long[] beiIds)
    {
        return toAjax(beiClientsService.deleteBeiClientsByIds(beiIds));
    }
}
